<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of sv</title>
  <meta name="keywords" content="sv">
  <meta name="description" content="Computes singular values of all unfoldings of a TT-tensor">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">@tt_tensor</a> &gt; sv.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/@tt_tensor&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>sv
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Computes singular values of all unfoldings of a TT-tensor</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [sval]=sv(tt) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">Computes singular values of all unfoldings of a TT-tensor
   [SVAL]=SV(TT) Computes all nonzero singular values of all unfoldings 
    and returns result as a cell array
    


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@qtt_tucker/diag.html" class="code" title="function [qt]=diag(qt)">diag</a>	Diagonal of a matrix or diagonal matrix from a vector in QTT-Tucker</li><li><a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>	Frobenius norm of the QTT-Tucker</li><li><a href="../../tt2/@tt_matrix/diag.html" class="code" title="function [tt]=diag(tm)">diag</a>	Extract the diagonal of the TT-matrix</li><li><a href="../../tt2/@tt_matrix/norm.html" class="code" title="function [nrm] = norm(t,varargin)">norm</a>	Matrix norm of the TT-matrix</li><li><a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>	Mode sizes of the TT-matrix</li><li><a href="diag.html" class="code" title="function [tm]=diag(tt)">diag</a>	Constructs diagonal TT-matrix from TT-tensor</li><li><a href="norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>	Frobenius norm of the TT-tensor</li><li><a href="qr.html" class="code" title="function [tt,rm]=qr(tt,op)">qr</a>	Left and right orthogonalization of the TT-format</li><li><a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>	Reshape of the TT-tensor</li><li><a href="size.html" class="code" title="function [sz] = size(tt,dim)">size</a>	Mode sizes of the TT-tensor</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/core/my_chop2.html" class="code" title="function [r] = my_chop2(sv,eps)">my_chop2</a>	Truncation by absolution precision in Frobenius norm</li><li><a href="../../tt2/solve/dmrg_eigb.html" class="code" title="function [y,ev] = dmrg_eigb(a,k,eps,varargin)">dmrg_eigb</a>	Find several minimal eigenvalues of a TT-matrix using DMRG method</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [sval]=sv(tt)</a>
0002 <span class="comment">%Computes singular values of all unfoldings of a TT-tensor</span>
0003 <span class="comment">%   [SVAL]=SV(TT) Computes all nonzero singular values of all unfoldings</span>
0004 <span class="comment">%    and returns result as a cell array</span>
0005 <span class="comment">%</span>
0006 <span class="comment">%</span>
0007 <span class="comment">%</span>
0008 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0009 <span class="comment">%</span>
0010 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0011 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0012 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0013 <span class="comment">%</span>
0014 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0015 <span class="comment">%ivan.oseledets@gmail.com</span>
0016 <span class="comment">%---------------------------</span>
0017 
0018 d=tt.d;
0019 n=tt.n;
0020 r=tt.r;
0021 pos=tt.ps;
0022 cr=tt.core;
0023 pos1=1;
0024 sval=cell(d-1,1);
0025 nrm=zeros(d,1);
0026 core0=cr(1:r(1)*n(1)*r(2));
0027 <span class="comment">%Orthogonalization from left-to-tight</span>
0028 <span class="keyword">for</span> i=1:d-1
0029    core0=<a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(core0,[r(i)*n(i),r(i+1)]);
0030    [core0,ru]=<a href="qr.html" class="code" title="function [tt,rm]=qr(tt,op)">qr</a>(core0,0); nrm(i+1)=<a href="norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(ru,<span class="string">'fro'</span>);
0031    ru=ru./nrm(i+1);
0032    core1=cr(pos(i+1):pos(i+2)-1);
0033    core1=<a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(core1,[r(i+1),n(i+1)*r(i+2)]);
0034    core1=ru*core1;
0035    r(i+1)=<a href="size.html" class="code" title="function [sz] = size(tt,dim)">size</a>(core0,2);
0036    cr(pos1:pos1-1+r(i)*n(i)*r(i+1))=core0(:);
0037    cr(pos1+r(i)*n(i)*r(i+1):pos1+r(i)*n(i)*r(i+1)+r(i+1)*n(i+1)*r(i+2)-1)=core1(:);
0038    core0=core1;
0039    pos1=pos1+r(i)*n(i)*r(i+1);
0040 <span class="keyword">end</span>
0041 pos1=pos1+r(d)*n(d)*r(d+1)-1;
0042 cr=cr(1:pos1); <span class="comment">%Truncate storage if required</span>
0043 pos=cumsum([1;n.*r(1:d).*r(2:d+1)]); 
0044 core0=cr(pos1-r(d)*n(d)*r(d+1)+1:pos1);
0045  <span class="keyword">for</span> i=d:-1:2
0046      <span class="comment">%core0=core(pos(i):pos(i+1)-1);</span>
0047      core1=cr(pos(i-1):pos(i)-1); 
0048      core0=<a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(core0,[r(i),n(i)*r(i+1)]);
0049      core1=<a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(core1,[r(i-1)*n(i-1),r(i)]);
0050      [u,s,v]=svd(core0,<span class="string">'econ'</span>);
0051      s=<a href="diag.html" class="code" title="function [tm]=diag(tt)">diag</a>(s); sval{i-1}=s; 
0052      r(i)=numel(s);
0053      u=u*<a href="diag.html" class="code" title="function [tm]=diag(tt)">diag</a>(s);
0054      core1=core1*u;
0055      core0=v';
0056      cr(pos1-r(i)*n(i)*r(i+1)+1:pos1)=core0(:);
0057      cr(pos1-r(i)*n(i)*r(i+1)-r(i-1)*n(i-1)*r(i)+1:pos1-r(i)*n(i)*r(i+1))=core1(:);
0058      <span class="comment">%cr=core(pos(i):pos(i+1)-1);</span>
0059      pos1=pos1-r(i)*n(i)*r(i+1);
0060      core0=core1;
0061  <span class="keyword">end</span>
0062  pos1=pos1-r(1)*n(1)*r(2);
0063  cr=cr(pos1+1:numel(cr)); <span class="comment">%Truncate unwanted elements;</span>
0064  tt.r=r;
0065  tt.ps=cumsum([1;tt.n.*tt.r(1:d).*tt.r(2:d+1)]);
0066  pp=cr(1:r(1)*n(1)*r(2));
0067  nrm(1)=<a href="norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(pp,<span class="string">'fro'</span>);
0068  cr(1:r(1)*n(1)*r(2))=pp./nrm(1);
0069  <span class="comment">%Now a simple trick: balance the product of numbers;</span>
0070  <span class="comment">%All cores are orthogonal except the first one. Thus, we know the norm</span>
0071  nrm0=sum(log(abs(nrm))); 
0072  nrm0=nrm0/d; nrm0=exp(nrm0);
0073  <span class="comment">%Construct normalization of norm</span>
0074  <span class="keyword">for</span> i=1:d-1
0075    nrm(i+1)=nrm(i+1)*nrm(i)/nrm0;
0076    nrm(i)=nrm0;
0077  <span class="keyword">end</span>
0078  <span class="comment">%Finally redistribute the norm</span>
0079  ps=tt.ps;
0080  <span class="keyword">for</span> i=1:d
0081     core1=cr(ps(i):ps(i+1)-1);
0082     core1=core1*nrm(i);
0083     cr(ps(i):ps(i+1)-1)=core1;
0084  <span class="keyword">end</span>
0085  tt.core=cr;
0086 <span class="keyword">return</span>
0087 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>